<?php

namespace app\admin\controller;

use think\Lang;

/**
 *服务人员实名认证
 */
class Fuaddress extends AdminControl {

    public function _initialize()
    {
        parent::_initialize();
        Lang::load(APP_PATH . 'admin/lang/'.config('default_lang').'/fupersonal.lang.php');
    }

    /**
     * 列表
     * @return mixed
     */
    public function index()
    {
        $model =model('fuaddress');
        $condition=[];
        $condition['fuwuid']=input('id');
        if (!empty(trim(input('search_provice'))))
        {
            $condition['a1.area_name'] = array('like','%'.trim(input('search_provice')).'%');
        }
        if (!empty(trim(input('search_city'))))
        {
            $condition['a2.area_name'] = array('like','%'.trim(input('search_city')).'%');
        }
        $filed='ds_fuwu_area.*,a1.area_name as area_name1,a2.area_name as area_name2';
        $data = $model->getList($condition,$filed,10);
        foreach ($data as $key=>$v){
            $ids = mb_substr(mb_substr($v['areaid'],1),0,-1);
            $areaArr = model('area')->getarea_list(['area_id'=>['in',$ids]],'area_name');
            $data[$key]['areastr'] = implode(',',array_column($areaArr,'area_name'));
        }
        $this->setAdminCurItem('address');
        $this->assign('search_provice',trim(input('search_provice')));
        $this->assign('search_city',trim(input('search_city')));
        $this->assign('id',input('id'));
        $this->assign('showpage',$model->page_info->render());
        $this->assign('data',$data);
        return $this->fetch();
    }
    /**
     * 区域修改
     */
    public function address_edit()
    {
        $model =model('fuaddress');
        if (request()->isPost()){
            $condition['id']=$_POST['id'];
            $areaids = ','.implode(',',$_POST['areaid']).',';
            $data=[
                'provice'=>$_POST['provice'],
                'city'=>$_POST['city'],
                'areaid'=>$areaids,
                'updated_at'=>date('Y-m-d H:i:s',time()),
                'status'=>$_POST['status'],
            ];
            $bool = $model->edit($condition,$data);
            if($bool){
                $fuwuid = $model->info($condition,'fuwuid');
                $this->log(lang('ds_edit') . lang('fuwu_personal_D').  '区域[' . input('post.id') . ']', 1);
                dsLayerOpenSuccess(lang('ds_common_save_succ'));
            }else{
                $this->error(lang('ds_common_save_fail'));
            }
        }else {

            $data = $model->info(['id' => input('id')]);
            $areamodel = model('area');
            $topArr = $areamodel->getarea_list(['area_id' => $data['provice']], 'area_id,area_name');#一级
            $twoArr = $areamodel->getarea_list(['area_id' => $data['city']], 'area_id,area_name');
            $threeArr = $areamodel->getarea_list(['area_parent_id' => $data['city']], 'area_id,area_name');
            $this->assign('topArr', $topArr);
            $this->assign('twoArr', $twoArr);
            $this->assign('threeArr', $threeArr);
            $this->assign('data', $data);
            $this->setAdminCurItem('address_edit');
            return $this->fetch();
        }
    }

    /**
     * 修改状态
     */
    public function edit_status()
    {
        $model = model('fuaddress');
        $condition['id'] = input('id');
        $data[input('column')] = input('value');
        $info = $model->edit($condition,$data);
        if ($info) {
            $this->log(lang('ds_edit') . lang('fuwu_personal_D') . '区域[ID:' . intval(input('id')) . ')', 1);
            ds_json_encode(10000, lang('ds_common_op_succ'));
        }else{
            $this->log(lang('ds_edit') . lang('fuwu_personal_D') . '区域[ID:' . intval(input('id')) . ')', 0);
            ds_json_encode(10001, lang('ds_common_op_fail'));
        }
    }


    /**
     * 获取卖家栏目列表,针对控制器下的栏目
     */
    protected function getAdminItemList() {
        $menu_array = array(
            array(
                'name' => 'index',
                'text' => lang('ds_manage'),
                'url' => url('Fupersonal/index'),
            ),
            array(
                'name' => 'add',
                'text' => lang('ds_add'),
                'url' => url('Fupersonal/add'),
            ),
            array(
                'name' => 'address',
                'text' => '服务人员区域列表',
                'url' => 'javascript:void(0)'
            ),
        );
        if (request()->action() =='view'){
            $menu_array[] = array(
                'name' => 'view',
                'text' => '查看审核',
                'url' => 'javascript:void(0)'
            );
        }
        return $menu_array;
    }
}

?>
